package com.coocaa.launcher.statusplugins.weather;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.coocaa.x.uipackage.SkinManager;
import com.skyworth.webSDK.webservice.weather.domian.DayWeather;
import com.tianci.appstore.R;
import com.tianci.appstore.utils.SkyConstants;

/**
 * Created by sunny on 15-7-14.
 */
public class WeatherView extends LinearLayout {
    //    private ImageView imgCity = null;
//    private TextView textCity = null;
    private ImageView imgWeather = null;
    private TextView textTemprature = null;
    private TextView textWeather = null;
    Context context;

    public WeatherView(Context context) {
        super(context);
        this.context = context;
        initView();
    }

    public WeatherView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initView();
    }

    public WeatherView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        initView();
    }

    private void initView() {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        this.setOrientation(LinearLayout.HORIZONTAL);
        this.setLayoutParams(params);
        this.setGravity(Gravity.CENTER);

//        imgCity = new ImageView(context);
//        FrameLayout.LayoutParams imgCityParams = new FrameLayout.LayoutParams(SkyConstants.Div(46), SkyConstants.Div(37));
//        addView(imgCity, imgCityParams);
//        textCity = new TextView(context);
//        textCity.setTextAppearance(context, R.style.statusbar_plugin_text_style);
//        textCity.setTextSize(SkyConstants.Dpi(32));
//        setMargin(textCity);
//        addView(textCity);

        textWeather = new TextView(context);
        textWeather.setTextAppearance(context, R.style.statusbar_plugin_text_style);
        textWeather.setTextSize(SkyConstants.Dpi(32));
//        setMargin(textWeather);
        LinearLayout.LayoutParams dayparams = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        dayparams.leftMargin = SkyConstants.Div(20);
        dayparams.rightMargin = SkyConstants.Div(20);
        textWeather.setLayoutParams(dayparams);
        addView(textWeather);

        imgWeather = new ImageView(context);
        FrameLayout.LayoutParams imgWeatherParams = new FrameLayout.LayoutParams(SkyConstants.Div(60), SkyConstants.Div(50));
        setMargin(imgWeather);
        addView(imgWeather, imgWeatherParams);

        textTemprature = new TextView(context);
        textTemprature.setTextAppearance(context, R.style.statusbar_plugin_text_style);
        textTemprature.setTextSize(SkyConstants.Dpi(32));
        setMargin(textTemprature);
        addView(textTemprature);
    }

    private void setMargin(View view) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT);
        params.leftMargin = SkyConstants.Div(20);
        view.setLayoutParams(params);
    }

    protected void setWeather(String city, DayWeather dayWeather, int index) {
        String weather = null;
        switch (dayWeather.WEnum) {
            case SUNNY: // 晴
                weather = "晴";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_sunny);
                break;
            case CLOUDY: // 多云
                weather = "多云";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_cloud);
                break;
            case OVERCAST: // 阴
                weather = "阴";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_cloud);
                break;
            case RAIN_SHOWER: // 阵雨
                weather = "阵雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_s);
                break;
            case RAIN_THUNDER: // 雷阵雨
                weather = "雷阵雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_thunder);
                break;
            case RAIN_HAILSTONE: // 雷阵雨伴有冰雹
                weather = "雷阵雨伴有冰雹";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_thunder);
                break;
            case RAIN_ICE: // 冻雨
                weather = "冻雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_s);
                break;
            case SLEET: // 雨夹雪
                weather = "雨夹雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_s);
                break;
            case RAIN_LIGHT: // 小雨
                weather = "小雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_s);
                break;
            case RAIN_MODERATE: // 中雨
                weather = "中雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_m);
                break;
            case RAIN_HEAVY: // 大雨
                weather = "大雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_l);
                break;
            case RAIN_VERY_HEAVY: // 暴雨
                weather = "暴雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_l);
                break;
            case RAIN_DOWNPOUR: // 大暴雨
                weather = "大暴雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_l);
                break;
            case RAIN_STORM: // 特大暴雨
                weather = "特大暴雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_l);
                break;
            case SNOW_SHOWER: // 阵雪
                weather = "阵雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_s);
                break;
            case SNOW_LIGHT: // 小雪
                weather = "小雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_s);
                break;
            case SNOW_MODERATE: // 中雪
                weather = "中雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_m);
                break;
            case SNOW_HEAVY: // 大雪
                weather = "大雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_l);
                break;
            case SNOW_STORM: // 暴雪
                weather = "暴雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_l);
                break;
            case FOG: // 雾
                weather = "雾";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_fog);
                break;
            case SAND_STORM: // 沙尘暴
                weather = "沙尘暴";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_fog);
                break;
            case DUSTY: // 浮尘
                weather = "浮尘";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_fog);
                break;
            case SAND_BLOWING: // 扬沙
                weather = "扬沙";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_fog);
                break;
            case SAND_STORM_STRONG: // 强沙尘暴
                weather = "强沙尘暴";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_fog);
                break;
            case RAIN_LIGHT_TO_MODERATE: // 小到中雨
                weather = "小到中雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_s);
                break;
            case RAIN_MODERATE_TO_HEAVY: // 中到大雨
                weather = "中到大雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_m);
                break;
            case RAIN_HEAVY_TO_STORM: // 大到暴雨
                weather = "大到暴雨";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_rain_l);
                break;
            case SNOW_LIGHT_TO_MODERATE: // 小到中雪
                weather = "小到中雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_s);
                break;
            case SNOW_MODERATE_TO_HEAVY: // 中到大雪
                weather = "中到大雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_m);
                break;
            case SNOW_HEAVY_TO_STORM: // 大到暴雪
                weather = "大到暴雪";
                SkinManager.getInstance().setBackgroundResource(imgWeather,
                        R.drawable.sp_weather_snow_l);
                break;
            default:
                break;
        }
//        textCity.setText(city);
        if (index == 0) {
            textWeather.setText("今");// textWeather.setText(weather);
        } else if (index == 1) {
            textWeather.setText("明");
        } else if (index == 2) {
            textWeather.setText("后");
        }
        String tempString = dayWeather.MinDegree + "℃" + "~" + dayWeather.MaxDegree + "℃";
        textTemprature.setText(tempString);
    }


}
